<!--
 * @Descripttion: (一级装箱/prod_one_pack)
 * @Author: (admin)
 * @Date: (2025-05-18)
-->
<template>
	<div>
		<el-form :model="queryParams" label-position="right" inline ref="queryRef" v-show="showSearch" @submit.prevent>
			<el-form-item label="DMS订单" prop="dmsOrderNo">
				<el-input v-model="queryParams.dmsOrderNo" placeholder="请输入DMS订单" />
			</el-form-item>
			<el-form-item label="计划号" prop="planNo">
				<el-input v-model="queryParams.planNo" placeholder="请输入计划号" />
			</el-form-item>
			<el-form-item label="装箱批次" prop="packBatchNo">
				<el-input v-model="queryParams.packBatchNo" placeholder="请输入装箱批次" />
			</el-form-item>
			<el-form-item label="箱号" prop="packNo">
				<el-input v-model="queryParams.packNo" placeholder="请输入箱号" />
			</el-form-item>
			<el-form-item label="装箱状态" prop="packStatus">
				<el-select clearable v-model="queryParams.packStatus" placeholder="请选择装箱状态">
					<el-option v-for="item in options.pack_status" :key="item.dictValue" :label="item.dictLabel"
						:value="item.dictValue">
						<span class="fl">{{ item.dictLabel }}</span>
						<span class="fr" style="color: var(--el-text-color-secondary);">{{ item.dictValue }}</span>
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="包装类型" prop="packingType">
				<el-select clearable v-model="queryParams.packingType" placeholder="请选择包装类型">
					<el-option v-for="item in options.packing_type" :key="item.dictValue" :label="item.dictLabel"
						:value="item.dictValue">
						<span class="fl">{{ item.dictLabel }}</span>
						<span class="fr" style="color: var(--el-text-color-secondary);">{{ item.dictValue }}</span>
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button icon="search" type="primary" @click="handleQuery">{{ $t('btn.search') }}</el-button>
				<el-button icon="refresh" @click="resetQuery">{{ $t('btn.reset') }}</el-button>
			</el-form-item>
		</el-form>
		<!-- 工具区域 -->
		<el-row :gutter="15" class="mb10">
			<el-col :span="1.5">
				<el-button type="primary" v-hasPermi="['prod:onePack:add']" plain icon="plus" @click="handleAdd">
					{{ $t('btn.add') }}
				</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="success" :disabled="single" v-hasPermi="['prod:onePack:edit']" plain icon="edit"
					@click="handleUpdate">
					{{ $t('btn.edit') }}
				</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="danger" :disabled="multiple" v-hasPermi="['prod:onePack:delete']" plain icon="delete"
					@click="handleDelete">
					{{ $t('btn.delete') }}
				</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-dropdown trigger="click" v-hasPermi="['prod:onePack:import']">
					<el-button type="primary" plain icon="Upload">
						{{ $t('btn.import') }}<el-icon class="el-icon--right"><arrow-down /></el-icon>
					</el-button>
					<template #dropdown>
						<el-dropdown-menu>
							<el-dropdown-item command="upload">
								<importData templateUrl="ProdManage/ProdOnePack/importTemplate"
									importUrl="/ProdManage/ProdOnePack/importData" @success="handleFileSuccess"></importData>
							</el-dropdown-item>
						</el-dropdown-menu>
					</template>
				</el-dropdown>
			</el-col>
			<el-col :span="1.5">
				<el-button type="warning" plain icon="download" @click="handleExport" v-hasPermi="['prod:onePack:export']">
					{{ $t('btn.export') }}
				</el-button>
			</el-col>
			<right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
		</el-row>

		<el-table :data="dataList" v-loading="loading" ref="table" border header-cell-class-name="el-table-header-cell"
			highlight-current-row @sort-change="sortChange" @selection-change="handleSelectionChange">
			<el-table-column prop="packId" label="包装id" fixed="left" align="center" :show-overflow-tooltip="true"
				v-if="columns.showColumn('packId')" />
			<el-table-column prop="dmsOrderNo" label="DMS订单" fixed="left" width="150" align="center"
				:show-overflow-tooltip="true" v-if="columns.showColumn('dmsOrderNo')" />
			<el-table-column prop="planNo" label="计划号" fixed="left" width="180" align="center" :show-overflow-tooltip="true"
				v-if="columns.showColumn('planNo')" />
			<el-table-column prop="packBatchNo" label="装箱批次" fixed="left" width="150" align="center"
				:show-overflow-tooltip="true" v-if="columns.showColumn('packBatchNo')" />
			<el-table-column prop="packNo" label="箱号" fixed="left" width="120" align="center" :show-overflow-tooltip="true"
				v-if="columns.showColumn('packNo')">
				<template #default="scope">
					<el-link type="primary" @click="handleDetail(scope.row)">{{ scope.row.packNo }}</el-link>
				</template>
			</el-table-column>
			<el-table-column prop="wareCode" label="仓库" width="100" align="center" :show-overflow-tooltip="true"
				v-if="columns.showColumn('wareCode')" />
			<el-table-column prop="packingType" label="包装类型" width="120" align="center"
				v-if="columns.showColumn('packingType')">
				<template #default="scope">
					<dict-tag :options="options.packing_type" :value="scope.row.packingType" />
				</template>
			</el-table-column>
			<el-table-column prop="packStatus" label="装箱状态" width="120" align="center"
				v-if="columns.showColumn('packStatus')">
				<template #default="scope">
					<dict-tag :options="options.pack_status" :value="scope.row.packStatus" />
				</template>
			</el-table-column>
			<el-table-column prop="packStartTime" label="装箱开始时间" width="160" :show-overflow-tooltip="true"
				v-if="columns.showColumn('packStartTime')" />
			<el-table-column prop="packEndTime" label="装箱结束时间" width="160" :show-overflow-tooltip="true"
				v-if="columns.showColumn('packEndTime')" />
			<el-table-column prop="packLength" label="长" width="80" align="center" v-if="columns.showColumn('packLength')" />
			<el-table-column prop="packWidth" label="宽" width="80" align="center" v-if="columns.showColumn('packWidth')" />
			<el-table-column prop="packHeight" label="高" width="80" align="center" v-if="columns.showColumn('packHeight')" />
			<el-table-column prop="packWeight" label="重" width="80" align="center" v-if="columns.showColumn('packWeight')" />
			<el-table-column prop="netWeight" label="净重" width="80" align="center" v-if="columns.showColumn('netWeight')" />
			<el-table-column prop="grossWeight" label="毛重" width="80" align="center"
				v-if="columns.showColumn('grossWeight')" />
			<el-table-column prop="groupId" label="填充件组ID" width="120" align="center" v-if="columns.showColumn('groupId')" />
			<el-table-column prop="groupCode" label="GroupCode" width="120" align="center" :show-overflow-tooltip="true"
				v-if="columns.showColumn('groupCode')" />
			<el-table-column prop="cancelUser" label="取消人" width="120" align="center" :show-overflow-tooltip="true"
				v-if="columns.showColumn('cancelUser')" />
			<el-table-column prop="cancelTime" label="取消时间" width="160" align="center"
				v-if="columns.showColumn('cancelTime')" />
			<el-table-column prop="serialNumber" label="SerialNumber" width="120" align="center"
				v-if="columns.showColumn('serialNumber')" />
			<el-table-column prop="version" label="版本" width="100" align="center" v-if="columns.showColumn('version')" />
			<el-table-column prop="sendFlag" label="发送qms标志" width="120" align="center" v-if="columns.showColumn('sendFlag')">
				<template #default="scope">
					<!-- <dict-tag :options="options.sendFlagOptions" :value="scope.row.sendFlag" /> -->
					<el-tag v-if="scope.row.sendFlag == false" type="warning">未发</el-tag>
					<el-tag v-else-if="scope.row.sendFlag == true" type="success">发送</el-tag>
				</template>
			</el-table-column>
			<el-table-column prop="carType" label="车型" width="120" align="center" v-if="columns.showColumn('carType')" />
			<el-table-column prop="technologyNo" label="工艺编号" width="120" align="center" :show-overflow-tooltip="true"
				v-if="columns.showColumn('technologyNo')" />
			<el-table-column prop="printState" label="打印状态" width="120" align="center"
				v-if="columns.showColumn('printState')">
				<template #default="scope">
					<dict-tag :options="options.print_state" :value="scope.row.printState" />
				</template>
			</el-table-column>
			<el-table-column prop="postbackState" label="上传状态" width="120" align="center"
				v-if="columns.showColumn('postbackState')">
				<template #default="scope">
					<dict-tag :options="options.postback_state" :value="scope.row.postbackState" />
				</template>
			</el-table-column>
			<el-table-column prop="remark" label="备注" width="120" align="center" :show-overflow-tooltip="true"
				v-if="columns.showColumn('remark')" />
			<el-table-column label="操作" width="200" fixed="right">
				<template #default="scope">
					<el-button-group>
						<el-button text v-hasPermi="['prod:onePack:edit']" type="success" icon="edit"
							@click="handleUpdate(scope.row)">
							{{ $t('btn.edit') }}
						</el-button>
						<el-button text v-hasPermi="['prod:onePack:delete']" type="danger" icon="delete"
							@click="handleDelete(scope.row)">
							{{ $t('btn.delete') }}
						</el-button>
						<el-button text v-hasPermi="['prod:onePackDetail:list']" icon="view" @click="rowClick(scope.row)">
							{{ $t('btn.details') }}
						</el-button>
					</el-button-group>
				</template>
			</el-table-column>
		</el-table>
		<pagination :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
			@pagination="getList" />

		<el-dialog draggable :close-on-click-modal="false" :title="title" :lock-scroll="false" v-model="open">
			<el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
				<el-row :gutter="20">
					<!-- <el-col :lg="12">
						<el-form-item label="包装id" prop="packId">
							<el-input v-model="form.packId" placeholder="请输入包装id" :disabled="opertype != 1" />
						</el-form-item>
					</el-col> -->
					<el-col :lg="12">
						<el-form-item label="DMS订单" prop="dmsOrderNo">
							<el-input v-model="form.dmsOrderNo" placeholder="请输入DMS订单" />
						</el-form-item>
					</el-col>
					<el-col :lg="12">
						<el-form-item label="计划号" prop="planNo">
							<el-input v-model="form.planNo" placeholder="请输入计划号" />
						</el-form-item>
					</el-col>
					<el-col :lg="12">
						<el-form-item label="仓库" prop="wareCode">
							<el-input v-model="form.wareCode" placeholder="请输入仓库" />
						</el-form-item>
					</el-col>
					<el-col :lg="12">
						<el-form-item label="装箱批次" prop="packBatchNo">
							<el-input v-model="form.packBatchNo" placeholder="请输入装箱批次" />
						</el-form-item>
					</el-col>
					<el-col :lg="12">
						<el-form-item label="箱号" prop="packNo">
							<el-input v-model="form.packNo" placeholder="请输入箱号" />
						</el-form-item>
					</el-col>
				</el-row>
				<el-row :gutter="20">
					<el-col :lg="12">
						<el-form-item label="装箱开始时间" prop="packStartTime">
							<el-date-picker v-model="form.packStartTime" type="datetime" placeholder="选择日期时间"
								value-format="YYYY-MM-DD HH:mm:ss" style="width: 100%;">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :lg="12">
						<el-form-item label="装箱结束时间" prop="packEndTime">
							<el-date-picker v-model="form.packEndTime" type="datetime" placeholder="选择日期时间"
								value-format="YYYY-MM-DD HH:mm:ss" style="width: 100%;">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :lg="12">
						<el-form-item label="装箱状态" prop="packStatus">
							<el-select v-model="form.packStatus" placeholder="请选择装箱状态" style="width: 100%;">
								<el-option v-for="item in options.pack_status" :key="item.dictValue" :label="item.dictLabel"
									:value="item.dictValue"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :lg="12">
						<el-form-item label="包装类型" prop="packingType">
							<el-select v-model="form.packingType" placeholder="请选择包装类型" style="width: 100%;">
								<el-option v-for="item in options.packing_type" :key="item.dictValue" :label="item.dictLabel"
									:value="item.dictValue"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :lg="8">
						<el-form-item label="长" prop="packLength">
							<el-input v-model="form.packLength" placeholder="请输入长" />
						</el-form-item>
					</el-col>
					<el-col :lg="8">
						<el-form-item label="宽" prop="packWidth">
							<el-input v-model="form.packWidth" placeholder="请输入宽" />
						</el-form-item>
					</el-col>
					<el-col :lg="8">
						<el-form-item label="高" prop="packHeight">
							<el-input v-model="form.packHeight" placeholder="请输入高" />
						</el-form-item>
					</el-col>
					<el-col :lg="8">
						<el-form-item label="重" prop="packWeight">
							<el-input v-model="form.packWeight" placeholder="请输入重" />
						</el-form-item>
					</el-col>
					<el-col :lg="8">
						<el-form-item label="净重" prop="netWeight">
							<el-input v-model="form.netWeight" placeholder="请输入净重" />
						</el-form-item>
					</el-col>
					<el-col :lg="8">
						<el-form-item label="毛重" prop="grossWeight">
							<el-input v-model="form.grossWeight" placeholder="请输入毛重" />
						</el-form-item>
					</el-col>
					<el-col :lg="12">
						<el-form-item label="取消人" prop="cancelUser">
							<el-input v-model.number="form.cancelUser" placeholder="请输入取消人" />
						</el-form-item>
					</el-col>
					<el-col :lg="12">
						<el-form-item label="取消时间" prop="cancelTime">
							<el-date-picker v-model="form.cancelTime" type="datetime" placeholder="选择取消时间"
								value-format="YYYY-MM-DD HH:mm:ss" style="width: 100%;">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :lg="12">
						<el-form-item label="SerialNumber" prop="serialNumber">
							<el-input v-model.number="form.serialNumber" placeholder="请输入SerialNumber" />
						</el-form-item>
					</el-col>
					<el-col :lg="12">
						<el-form-item label="版本" prop="version">
							<el-input v-model.number="form.version" placeholder="请输入版本" />
						</el-form-item>
					</el-col>
					<el-col :lg="12">
						<el-form-item label="填充件组ID" prop="groupId">
							<el-input v-model.number="form.groupId" placeholder="请输入填充件组ID" />
						</el-form-item>
					</el-col>
					<el-col :lg="12">
						<el-form-item label="GroupCode" prop="groupCode">
							<el-input v-model="form.groupCode" placeholder="请输入GroupCode" />
						</el-form-item>
					</el-col>
					<el-col :lg="12">
						<el-form-item label="车型" prop="carType">
							<el-input v-model="form.carType" placeholder="请输入车型" />
						</el-form-item>
					</el-col>
					<el-col :lg="12">
						<el-form-item label="工艺编号" prop="technologyNo">
							<el-input v-model="form.technologyNo" placeholder="请输入工艺编号" />
						</el-form-item>
					</el-col>
				</el-row>
				<el-row :gutter="20">
					<el-col :lg="24">
						<el-form-item label="发送qms标志" prop="sendFlag">
							<el-radio-group v-model="form.sendFlag">
								<el-radio v-for="item in options.sendFlagOptions" :key="item.dictValue" :value="item.dictValue">
									{{ item.dictLabel }}
								</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :lg="12">
						<el-form-item label="打印状态" prop="printState">
							<el-radio-group v-model="form.printState">
								<el-radio v-for="item in options.print_state" :key="item.dictValue" :value="item.dictValue">
									{{ item.dictLabel }}
								</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :lg="12">
						<el-form-item label="上传状态" prop="postbackState">
							<el-radio-group v-model="form.postbackState">
								<el-radio v-for="item in options.postback_state" :key="item.dictValue" :value="item.dictValue">
									{{ item.dictLabel }}
								</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :lg="24">
						<el-form-item label="备注" prop="remark">
							<el-input type="textarea" v-model="form.remark" placeholder="请输入备注" />
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<template #footer v-if="opertype != 3">
				<el-button text @click="cancel">{{ $t('btn.cancel') }}</el-button>
				<el-button type="primary" @click="submitForm">{{ $t('btn.submit') }}</el-button>
			</template>
		</el-dialog>

		<!-- 明细信息 -->
		<el-drawer v-model="drawer" size="60%" direction="rtl">
			<el-table :data="prodOnePackDetailList" header-row-class-name="text-navy">
				<el-table-column label="序号" type="index" width="80" />
				<el-table-column prop="partCode" label="物料" width="160" align="center" />
				<el-table-column prop="packNum" label="装箱数量" width="120" align="center" />
				<el-table-column prop="orgCode" label="组织" width="160" align="center" />
				<el-table-column prop="supplierCode" label="供应商" width="160" align="center" />
				<el-table-column prop="packTime" label="装箱时间" width="160" />
				<el-table-column prop="packUserId" label="装箱人" width="120" />
				<el-table-column prop="itemStatus" label="明细状态" width="120" align="center"
					v-if="columns.showColumn('itemStatus')">
					<template #default="scope">
						<dict-tag :options="options.pack_item_status" :value="scope.row.itemStatus" />
					</template>
				</el-table-column>
			</el-table>
			<pagination :total="detailTotal" v-model:page="queryDetailParams.pageNum"
				v-model:limit="queryDetailParams.pageSize" @pagination="getDetailList" />
		</el-drawer>
	</div>
</template>

<script setup name="prodonepack">
import {
	pageProdOnePack,
	addProdOnePack, delProdOnePack,
	updateProdOnePack, getProdOnePack,
}
	from '@/api/prodManage/prodOnePack.js'
import {
	pageProdOnePackDetail
}
	from '@/api/prodManage/prodOnePackDetail.js'
import importData from '@/components/ImportData'
const { proxy } = getCurrentInstance()
const ids = ref([])
const loading = ref(false)
const showSearch = ref(true)
const queryParams = reactive({
	pageNum: 1,
	pageSize: 10,
	sort: '',
	sortType: 'asc',
	dmsOrderNo: undefined,
	planNo: undefined,
	packBatchNo: undefined,
	packNo: undefined,
	packStatus: undefined,
	packingType: undefined,
})
const columns = ref([
	{ visible: false, prop: 'packId', label: '包装id' },
	{ visible: true, prop: 'dmsOrderNo', label: 'DMS订单' },
	{ visible: true, prop: 'planNo', label: '计划号' },
	{ visible: true, prop: 'wareCode', label: '仓库' },
	{ visible: true, prop: 'packBatchNo', label: '装箱批次' },
	{ visible: true, prop: 'packNo', label: '箱号' },
	{ visible: true, prop: 'packStartTime', label: '装箱开始时间' },
	{ visible: true, prop: 'packEndTime', label: '装箱结束时间' },
	{ visible: true, prop: 'packStatus', label: '装箱状态' },
	{ visible: true, prop: 'packingType', label: '包装类型' },
	{ visible: true, prop: 'packLength', label: '长' },
	{ visible: true, prop: 'packWidth', label: '宽' },
	{ visible: true, prop: 'packHeight', label: '高' },
	{ visible: true, prop: 'packWeight', label: '重' },
	{ visible: true, prop: 'netWeight', label: '净重' },
	{ visible: true, prop: 'grossWeight', label: '毛重' },
	{ visible: true, prop: 'groupCode', label: 'GroupCode' },
	{ visible: true, prop: 'cancelUser', label: '取消人' },
	{ visible: true, prop: 'cancelTime', label: '取消时间' },
	{ visible: true, prop: 'serialNumber', label: 'SerialNumber' },
	{ visible: true, prop: 'groupId', label: '填充件组ID' },
	{ visible: true, prop: 'version', label: '版本' },
	{ visible: true, prop: 'sendFlag', label: '发送qms标志' },
	{ visible: true, prop: 'carType', label: '车型' },
	{ visible: true, prop: 'technologyNo', label: '工艺编号' },
	{ visible: true, prop: 'printState', label: '打印状态' },
	{ visible: true, prop: 'postbackState', label: '上传状态' },
	{ visible: true, prop: 'remark', label: '备注' },
])
const total = ref(0)
const dataList = ref([])
const queryRef = ref()
const defaultTime = ref([new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)])


var dictParams = [
	"pack_status",
	"packing_type",
	"print_state",
	"postback_state",
	"pack_item_status",
]

proxy.getDicts(dictParams).then((response) => {
	response.data.forEach((element) => {
		state.options[element.dictType] = element.list
	})
})

function getList() {
	loading.value = true
	pageProdOnePack(queryParams).then(res => {
		const { code, data } = res
		if (code == 200) {
			dataList.value = data.result
			total.value = data.totalNum
			loading.value = false
		}
	})
}

// 查询
function handleQuery() {
	queryParams.pageNum = 1
	getList()
}

// 重置查询操作
function resetQuery() {
	proxy.resetForm("queryRef")
	handleQuery()
}
// 多选框选中数据
function handleSelectionChange(selection) {
	ids.value = selection.map((item) => item.packId);
	single.value = selection.length != 1
	multiple.value = !selection.length;
}
// 自定义排序
function sortChange(column) {
	var sort = undefined
	var sortType = undefined

	if (column.prop != null && column.order != null) {
		sort = column.prop
		sortType = column.order

	}
	queryParams.sort = sort
	queryParams.sortType = sortType
	handleQuery()
}
// 查看明细
const router = useRouter()
function handleDetail(row) {
	if (!row) {
		proxy.$modal.msgError(`订单信息无效!`)
	}
	router.push({ path: '/prodManage/prodOnePackDetail', query: { packId: row.packId } })
}


/*************** form操作 ***************/
const formRef = ref()
const title = ref('')
// 操作类型 1、add 2、edit 3、view
const opertype = ref(0)
const open = ref(false)
const state = reactive({
	single: true,
	multiple: true,
	form: {},
	rules: {
		packId: [{ required: true, message: "包装id不能为空", trigger: "blur" }],
		dmsOrderNo: [{ required: true, message: "DMS订单不能为空", trigger: "blur" }],
		planNo: [{ required: true, message: "计划号不能为空", trigger: "blur" }],
		packBatchNo: [{ required: true, message: "装箱批次不能为空", trigger: "blur" }],
		packNo: [{ required: true, message: "箱号不能为空", trigger: "blur" }],
		packStatus: [{ required: true, message: "装箱状态不能为空", trigger: "change" }],
		packingType: [{ required: true, message: "包装类型不能为空", trigger: "change" }],
		printState: [{ required: true, message: "打印状态不能为空", trigger: "change" }],
		postbackState: [{ required: true, message: "上传状态不能为空", trigger: "change" }],
	},
	options: {
		// 装箱状态
		pack_status: [],
		// 包装类型 
		packing_type: [],
		// 打印状态 
		print_state: [],
		// 上传状态 
		postback_state: [],
		// 发送qms标志（0：未发，1：发送）  格式 eg:{ dictLabel: '标签', dictValue: '0'}
		sendFlagOptions: [
			{ dictLabel: '未发', dictValue: false, listClass: 'warning' },
			{ dictLabel: '发送', dictValue: true, listClass: 'success' }
		],
		//明细状态
		pack_item_status: [],
	}
})

const { form, rules, options, single, multiple } = toRefs(state)

// 关闭dialog
function cancel() {
	open.value = false
	reset()
}

// 重置表单
function reset() {
	form.value = {
		packId: null,
		dmsOrderNo: null,
		planNo: null,
		wareCode: null,
		packBatchNo: null,
		packNo: null,
		packStartTime: null,
		packEndTime: null,
		packStatus: null,
		packingType: null,
		packLength: null,
		packWidth: null,
		packHeight: null,
		packWeight: null,
		netWeight: null,
		grossWeight: null,
		groupCode: null,
		cancelUser: null,
		cancelTime: null,
		serialNumber: null,
		groupId: null,
		version: null,
		sendFlag: null,
		carType: null,
		technologyNo: null,
		printState: null,
		postbackState: null,
		createBy: null,
		createTime: null,
		updateBy: null,
		updateTime: null,
		remark: null,
	};
	proxy.resetForm("formRef")
}


// 添加按钮操作
function handleAdd() {
	reset();
	open.value = true
	title.value = '添加一级装箱'
	opertype.value = 1
	form.value.packId = proxy.parseGuid();
}
// 修改按钮操作
function handleUpdate(row) {
	reset()
	const id = row.packId || ids.value
	getProdOnePack(id).then((res) => {
		const { code, data } = res
		if (code == 200) {
			open.value = true
			title.value = '修改一级装箱'
			opertype.value = 2

			form.value = {
				...data,
			}
		}
	})
}

// 添加&修改 表单提交
function submitForm() {
	proxy.$refs["formRef"].validate((valid) => {
		if (valid) {

			if (form.value.packId != undefined && opertype.value === 2) {
				updateProdOnePack(form.value).then((res) => {
					proxy.$modal.msgSuccess("修改成功")
					open.value = false
					getList()
				})
			} else {
				addProdOnePack(form.value).then((res) => {
					proxy.$modal.msgSuccess("新增成功")
					open.value = false
					getList()
				})
			}
		}
	})
}

// 删除按钮操作
function handleDelete(row) {
	const Ids = row.packId ? [row.packId] : undefined || ids.value
	proxy
		.$confirm('是否确认删除"' + Ids.length + '"条数据项？', "警告", {
			confirmButtonText: proxy.$t('common.ok'),
			cancelButtonText: proxy.$t('common.cancel'),
			type: "warning",
		})
		.then(function () {
			return delProdOnePack(Ids)
		})
		.then(() => {
			getList()
			proxy.$modal.msgSuccess("删除成功")
		})
}


// 导入数据成功处理
const handleFileSuccess = (response) => {
	const { item1, item2 } = response.data
	var error = ''
	item2.forEach((item) => {
		error += item.storageMessage + ','
	})
	proxy.$alert(item1 + '<p>' + error + '</p>', '导入结果', {
		dangerouslyUseHTMLString: true
	})
	getList()
}

// 导出按钮操作
function handleExport() {
	proxy
		.$confirm("是否确认导出一级装箱数据项?", "警告", {
			confirmButtonText: "确定",
			cancelButtonText: "取消",
			type: "warning",
		})
		.then(async () => {
			await proxy.downFile('/ProdManage/ProdOnePack/export', { ...queryParams })
		})
}

/*********************一级包装明细子表信息*************************/
const detailTotal = ref(0)
const prodOnePackDetailList = ref([])
const drawer = ref(false)
const queryDetailParams = reactive({
	pageNum: 1,
	pageSize: 10,
	sort: '',
	sortType: 'asc',
	onePackId: undefined,
})
/** 一级包装明细详情 */
function rowClick(row) {
	const id = row.packId
	if (!id) return;
	queryDetailParams.onePackId = id
	queryDetailParams.pageNum = 1
	getDetailList()
}
//获取明细
function getDetailList() {
	pageProdOnePackDetail(queryDetailParams).then(res => {
		const { code, data } = res
		if (code == 200) {
			prodOnePackDetailList.value = data.result
			detailTotal.value = data.totalNum
			drawer.value = true
		}
	})
}

handleQuery()
</script>